package org.blast.parser.main;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import org.blast.parser.objects.BlastOutput;
import org.blast.parser.objects.Hit;
import org.blast.parser.objects.Hsp;
import org.blast.parser.objects.Iteration;

public class TestMarshal {

	public static void main(String[] args) {

		BlastOutput blastOutput = new BlastOutput();

		blastOutput.setBlastOutput_db("database");
		blastOutput.setBlastOutput_program("program");
		blastOutput.setBlastOutput_query_def("query def");
		blastOutput.setBlastOutput_query_ID("id");
		blastOutput.setBlastOutput_query_len("q len");
		blastOutput.setBlastOutput_reference("reference");
		blastOutput.setBlastOutput_version("version");
		
		List<Iteration> iterations = new ArrayList<Iteration>();
		List<Hit> hits = new ArrayList<Hit>();
		List<Hsp> hsps = new ArrayList<Hsp>();
		
		Iteration i = new Iteration();
		Hit hit = new Hit();
		Hsp hsp = new Hsp();
		
		iterations.add(i);
		i.setIteration_hits(hits);
		hits.add(hit);
		hit.setHit_hsps(hsps);
		hsps.add(hsp);
		
		hsp.setHsp_align_len(42);
		hsp.setHsp_bit_score(1.414);
		
		blastOutput.setBlastOutput_iterations(iterations);


		try {

			File file = new File("/Volumes/Axolotl/tmp/testoutputxmlfile.xml");
			//JAXBContext jaxbContext = JAXBContext.newInstance(BlastOutput.class);
			Marshaller jaxbMarshaller = JAXBContext.newInstance(BlastOutput.class).createMarshaller();

			// output pretty printed
			jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

			jaxbMarshaller.marshal(blastOutput, file);
			jaxbMarshaller.marshal(blastOutput, System.out);

		} catch (JAXBException e) {
			e.printStackTrace();
		}

	}

}
